package com.bailiban.utils;

import io.swagger.annotations.ApiModel;
import io.swagger.annotations.ApiModelProperty;
import lombok.Data;

/**
 * @author zhulang
 * @Classname Result
 * @Description TODO
 * @Date 2020/3/18 23:20
 */
@Data
@ApiModel(description = "响应的结果类")
public class Result {
    /**
     * 响应状态码
     */
    @ApiModelProperty(name = "code",value = "响应状态码")
    private Integer code;
    /**
     * 响应的消息
     */
    @ApiModelProperty(name = "message",value = "响应的消息")
    private String message;
    /**
     * 响应是否成功
     */
    @ApiModelProperty(name = "success",value = "响应成功与否")
    private Boolean success;
    /**
     * 响应的封装的数据
     */
    @ApiModelProperty(name = "data",value = "响应的数据",dataType = "object")
    private Object data;
    public Result(ResultCode resultCode, Object data) {
        this.code = resultCode.getCode();
        this.message = resultCode.getMessage();
        this.success = resultCode.getSuccess();
        this.data = data;
    }
    public Result(ResultCode resultCode) {
        this.code = resultCode.getCode();
        this.message = resultCode.getMessage();
        this.success = resultCode.getSuccess();
    }
    public Result() {
    }
    /**
     * 返回成功
     *
     * @return
     */
    public static Result success() {
        Result result = new Result(ResultCode.SUCCESS);
        return result;
    }
    /**
     * 返回成功，并携带数据
     *
     * @param data
     * @return
     */
    public static Result success(Object data) {
        Result result = new Result(ResultCode.SUCCESS, data);
        return result;
    }
    /**
     * 返回失败
     *
     * @param resultCode
     * @return
     */
    public static Result failure(ResultCode resultCode) {
        Result result = new Result(resultCode);
        return result;
    }
    /**
     * 返回失败，并携带数据
     *
     * @param resultCode
     * @param data
     * @return
     */
    public static Result failure(ResultCode resultCode, Object data) {
        Result result = new Result(resultCode, data);
        return result;
    }


}
